<?php
/**
 * Created by PhpStorm.
 * User: hda
 * Date: 2017/5/18
 * Time: 下午5:08
 */

namespace library\order;


class format
{

//    外卖订单状态

    private static $ORDER_STATUS = [
        '0' => ['未配送'],
        '1' => ['正在配送'],
        '2' => ['申请取消'],
        '3' => ['确定取消'],
        '4' => ['取消订单'],
        '5' => ['货到付款(未配送)'],
        '6' => ['正在配送(货到付款)'],
        '7' => ['已收货']
    ];

    /**
     * 格式化状态
     */
    public static function order_status($status, $key = 0)
    {
        $array = self::$ORDER_STATUS;
        $status = strval($status);
        $key = intval($key);
        if (!empty($array[$status][$key])) {
            return $array[$status][$key];
        } else {
            return $array[$status][0];
        }

    }

    /**
     * 格式化状态列表
     */
    public static function get_order_status($key = 0)
    {
        $array = [];
        $list = self::$ORDER_STATUS;
        foreach ($list as $k => $arr) {
            $val = $arr[0];
            if (!empty($arr[$key])) {
                $val = $arr[$key];
            }
            $brr = [
                'status' => $k,
                'text' => $val
            ];
            array_push($array, $brr);
        }
        return $array;
    }
}